package Controls
{
	import Input.GameInput;
	
	import Native.NativeField;
	
	import Objects.GameBitmap;
	import Objects.GameObject;
	import Objects.GameSprite;
	import Objects.GameTextField;
	
	import flash.geom.Rectangle;
	import flash.text.TextField;

	public class ScrollBar extends GameSprite
	{
		public var track:GameBitmap;
		public var arrow1:Button;
		public var arrow2:Button;
		public var slider:Button;
		protected var target:GameObject;
		protected var visibleRect:Rectangle;
		protected var scrollRect:Rectangle;
		protected var dragRect:Rectangle;
		public var arrowStep:int=10;
		public function ScrollBar()
		{
			super();
			
			intelligent=true;
			
			dragRect=new Rectangle();
			visibleRect=new Rectangle();
			scrollRect=new Rectangle();
			
			track=new GameBitmap();
			addChild(track);
			
			arrow1=new Button();
			addChild(arrow1);
			
			arrow2=new Button();
			addChild(arrow2);
			
			slider=new Button();
			addChild(slider);
		}
		override protected function $update():void
		{
			if(arrow1.mHit)
			{
				doArrow1Command();
			}
			
			if(arrow2.mHit)
			{
				doArrow2Command();
			}
			if(GameInput.i.mDown)
			{
				if(mOver)
				{
					slider.sprite.startDrag(false,dragRect);
				}
			}
			else
			{
				slider.sprite.stopDrag();
			}
			syncScroll();
		}
		protected function lockSlider():void
		{
			
		}
		protected function doArrow1Command():void
		{
			
		}
		protected function doArrow2Command():void
		{
			
		}
		private final function syncScroll():void
		{
			if(target)
			{
				if(target is GameTextField)
				{
					syncFieldScroll();
				}
				else
				{
					syncNormalScroll();
				}
			}
		}
		protected function syncNormalScroll():void
		{
			
		}
		protected function syncFieldScroll():void
		{
			
		}
		public function register(_target:GameObject,width:int=0,height:int=0):void
		{
			target=_target;
			if(target is GameTextField)
			{
				visibleRect.width=target.obj.width;
				visibleRect.height=target.obj.height;
			}
			else
			{
				visibleRect.width=width;
				visibleRect.height=height;
			}
		}
		public function setup(width:Number,height:Number):void
		{
			
		}
		
		public function scrollPercent(percent:Number):void
		{
			
		}
	}
}